package com.tanhua.server.controller;

import com.tanhua.server.service.TodayBestService;
import com.tanhua.server.utils.Cache;
import com.tanhua.server.vo.NearUserVo;
import com.tanhua.server.vo.PageResult;
import com.tanhua.server.vo.RecommendUserQueryParam;
import com.tanhua.server.vo.TodayBest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: Administrator
 * @date: Created in 2021/2/15 12:27
 * @version: 0.0.1
 * @modified By:
 */
@RestController
@RequestMapping("/tanhua")
@Slf4j
public class TodayBestController {
    @Autowired
    private TodayBestService todayBestService;



    /**
     * @description 查询今日佳人
     * @author
     * @date
     * @param
     *@return
     */
    @GetMapping("/todayBest")
    public ResponseEntity<TodayBest> queryTodayBest(){
        try {
            TodayBest todayBest=this.todayBestService.queryTodayBest();
            if(null!=todayBest){
                return ResponseEntity.ok(todayBest);
            }
        } catch (Exception e) {
            log.error("查询今日佳人出错~",e);
        }
      return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
    /**
     * @description  查询推荐用户列表
     * @author
     * @date
     * @param
     *@return
     */
    @GetMapping("/recommendation")
    @Cache
    public ResponseEntity<PageResult>queryRecommendation( RecommendUserQueryParam queryParam){
        try {
            PageResult pageResult=this.todayBestService.queryRecommendation(queryParam);
            if(null!=pageResult){
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            log.error("查询推荐用户列表出错~",e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
    /**
     * @description 查询今日佳人详情
     * @author
     * @date
     * @param
     *@return
     */
    @GetMapping("{id}/personalInfo")
    public ResponseEntity<TodayBest>queryTodayBest(@PathVariable("id")Long userId){
        try {
            TodayBest todayBest = this.todayBestService.queryTodayBest(userId);
            if(null!=todayBest){
                return ResponseEntity.ok(todayBest);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
    /**
     * @description 查询陌生人问题
     * @author
     * @date
     * @param
     *@return
     */
    @GetMapping("strangerQuestions")
    public ResponseEntity<String>queryStrangerQuestions(@RequestParam(value = "userId")Long userId){
        try {
            String question= this.todayBestService.queryStrangerQuestions(userId);
            if(StringUtils.isNotEmpty(question)){
                return ResponseEntity.ok(question);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
    /**
     * @description 恢复陌生人问题
     * @author
     * @date
     * @param
     *@return
     */
    @PostMapping("strangerQuestions")
    public ResponseEntity<Void>replyQuestions(@RequestBody Map<String,Object>param){
        try {
            Long userId = Long.valueOf(param.get("userId").toString());
            String reply = param.get("reply").toString();
            Boolean bool=this.todayBestService.replyQuestions(userId,reply);
            if(bool){
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    @GetMapping("search")
    public ResponseEntity<List<NearUserVo>>queryNearUser(@RequestParam(value = "gender",required = false)String gender,
                                                     @RequestParam(value = "distance",defaultValue = "2000")String distance){
        try {
            List<NearUserVo>nearUserVos= this.todayBestService.queryNearUser(gender,distance);
            if(CollectionUtils.isNotEmpty(nearUserVos)){
                return ResponseEntity.ok(nearUserVos);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * @description 左滑右滑
     * @author
     * @date
     * @param
     *@return
     */
    @GetMapping("cards")
    public ResponseEntity<List<TodayBest>>queryCardsList(){
        try {
            List<TodayBest>todayBestList= this.todayBestService.queryCardsList();
            if(CollectionUtils.isNotEmpty(todayBestList)){
                return ResponseEntity.ok(todayBestList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * @description 喜欢
     * @author
     * @date
     * @param
     *@return
     */
    @GetMapping("{id}/love")
    public ResponseEntity<Void>likeUser(@PathVariable("id")Long likeUserId){
        try {
            Boolean bool= this.todayBestService.likeUser(likeUserId);
            if(bool){
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * @description 不喜欢
     * @author
     * @date
     * @param
     *@return
     */
    @GetMapping("{id}/unlove")
    public ResponseEntity<Void>disLikeUser(@PathVariable("id")Long likeUserId){
        try {
            Boolean bool=this.todayBestService.disLikeUser(likeUserId);
            if(bool){
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();

    }
}
